package test;
import lib.db_properties_path.*;
import java.sql.*;
import java.util.*;
import lib.dbTool.*;


public class EATMEDICINE extends DBconnection2 {
public EATMEDICINE(SetPath set){
super(set);
}
public EATMEDICINE(){
super(new DefaultSetPath());
}
/** Auto Increasment */
/** Primary Key */
/** int identity ; java.lang.Integer */private int idmedicine;
/** nvarchar ; java.lang.String */private String onoffmedicine;
/** nvarchar ; java.lang.String */private String sun;
/** nvarchar ; java.lang.String */private String mon;
/** nvarchar ; java.lang.String */private String tue;
/** nvarchar ; java.lang.String */private String wed;
/** nvarchar ; java.lang.String */private String thu;
/** nvarchar ; java.lang.String */private String fri;
/** nvarchar ; java.lang.String */private String sat;
/** bigint ; java.lang.Long */private String timemedicine;
/** nvarchar ; java.lang.String */private String picturemedicine;
/** nvarchar ; java.lang.String */private String audiomedicine;
/** int ; java.lang.Integer */private int idoldman;
public int getIdmedicine(){
return  idmedicine;
}
public void setIdmedicine(int idmedicine){
this.idmedicine= idmedicine;
}

public String getOnoffmedicine(){
return  onoffmedicine;
}
public void setOnoffmedicine(String onoffmedicine){
this.onoffmedicine= onoffmedicine;
}

public String getSun(){
return  sun;
}
public void setSun(String sun){
this.sun= sun;
}

public String getMon(){
return  mon;
}
public void setMon(String mon){
this.mon= mon;
}

public String getTue(){
return  tue;
}
public void setTue(String tue){
this.tue= tue;
}

public String getWed(){
return  wed;
}
public void setWed(String wed){
this.wed= wed;
}

public String getThu(){
return  thu;
}
public void setThu(String thu){
this.thu= thu;
}

public String getFri(){
return  fri;
}
public void setFri(String fri){
this.fri= fri;
}

public String getSat(){
return  sat;
}
public void setSat(String sat){
this.sat= sat;
}

public String getTimemedicine(){
return  timemedicine;
}
public void setTimemedicine(String timemedicine){
this.timemedicine= timemedicine;
}

public String getPicturemedicine(){
return  picturemedicine;
}
public void setPicturemedicine(String picturemedicine){
this.picturemedicine= picturemedicine;
}

public String getAudiomedicine(){
return  audiomedicine;
}
public void setAudiomedicine(String audiomedicine){
this.audiomedicine= audiomedicine;
}

public int getIdoldman(){
return  idoldman;
}
public void setIdoldman(int idoldman){
this.idoldman= idoldman;
}

public interface fn{
String TABLE_NAME = "EATMEDICINE";
String PK = "idmedicine";
String idmedicine="idmedicine";
String onoffmedicine="onoffmedicine";
String sun="sun";
String mon="mon";
String tue="tue";
String wed="wed";
String thu="thu";
String fri="fri";
String sat="sat";
String timemedicine="timemedicine";
String picturemedicine="picturemedicine";
String audiomedicine="audiomedicine";
String idoldman="idoldman";
}
public String sql(String SQL){
return Utility.getSQL組合字(SQL, EATMEDICINE.fn.class);
}
public int clear() {
String SQL = "delete from EATMEDICINE";
Object parameter[] = {};
return super.excuteUpdate(SQL, parameter);
}

public int delete(int idmedicine) {
String SQL = "delete from EATMEDICINE where idmedicine=?";
Object parameter[] = {idmedicine};
return super.excuteUpdate(SQL, parameter);
}

public int update(String onoffmedicine,String sun,String mon,String tue,String wed,String thu,String fri,String sat,String timemedicine,String picturemedicine,String audiomedicine,int idoldman, int idmedicine){
String SQL = "update EATMEDICINE set onoffmedicine=?,sun=?,mon=?,tue=?,wed=?,thu=?,fri=?,sat=?,timemedicine=?,picturemedicine=?,audiomedicine=?,idoldman=? where idmedicine=?";
Object parameter[] = {onoffmedicine,sun,mon,tue,wed,thu,fri,sat,timemedicine,picturemedicine,audiomedicine,idoldman,idmedicine};
return super.excuteUpdate(SQL,parameter);
}

public int insert(String onoffmedicine,String sun,String mon,String tue,String wed,String thu,String fri,String sat,String timemedicine,String picturemedicine,String audiomedicine,int idoldman){
String SQL = "insert into EATMEDICINE(onoffmedicine,sun,mon,tue,wed,thu,fri,sat,timemedicine,picturemedicine,audiomedicine,idoldman) values(?,?,?,?,?,?,?,?,?,?,?,?)";
Object parameter[] = { onoffmedicine,sun,mon,tue,wed,thu,fri,sat,timemedicine,picturemedicine,audiomedicine,idoldman};
return super.excuteUpdate(SQL ,parameter);
}

public String[][] select() {
String SQL = "select * from EATMEDICINE";
Object parameter[] = {};
return super.select(SQL, parameter);
}

public EATMEDICINE[] select_Object() {
String SQL = "select * from EATMEDICINE";
Object parameter[] = {};
String data[][] = super.select(SQL, parameter);EATMEDICINE obj[] = toObject(data);return obj;}

public String[][] select( int idmedicine) {
String SQL = "select * from EATMEDICINE where idmedicine=?";
Object parameter[] = {idmedicine};
return super.select(SQL, parameter);}

public EATMEDICINE[] select_Object( int idmedicine) {
String data[][] = this.select(idmedicine);EATMEDICINE obj[] = toObject(data);return obj;}

public int selectCount() {
String SQL = "select count(idmedicine) from EATMEDICINE";
Object parameter[] = {};
String d[][] = super.select(SQL, parameter);
return Integer.parseInt(d[0][0]);}

public String[][] selectPage(int pageSize, int pageIndex, int rowCount) {
int desc = PaggingSQL.ASC;PaggingSQL ps = new lib.dbTool.MsSQL2012();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;String SQL = ps.getSelectPage(pageSize, pageIndex, TABLE_NAME, PK, desc, rowCount);Object parameter[] = {};
return super.select(SQL, parameter);
}
public String[][] selectPageOrderBy(int pageSize, int pageIndex, String sortName, int desc, int rowCount) {
PaggingSQL ps = new lib.dbTool.MsSQL2012();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;String SQL = ps.getSelectPageOrderBy(pageSize, pageIndex, TABLE_NAME, PK, sortName, desc, rowCount);Object parameter[] = {};
return super.select(SQL, parameter);
}
 /**
 * 關鍵字 where 不用寫
 * @param pageSize
 * @param pageIndex
 * @param sortName
 * @param desc
 * @param rowCount
 * @param whereCondition = 【pk>0】, 關鍵字 where 不用寫
 * @return
 */
public String[][] selectPageOrderBy(int pageSize, int pageIndex, String sortName, int desc, int rowCount, String whereCondition) {
PaggingSQL ps = new lib.dbTool.MsSQL2012();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;
//範例,關鍵字 where 不用寫, ex:【pk>0】
String SQL = ps.getSelectPageOrderBy(pageSize, pageIndex, TABLE_NAME, PK, sortName, desc, rowCount, whereCondition);Object parameter[] = {};
return super.select(SQL, parameter);
}
public EATMEDICINE[] selectPage_Object(int pageSize, int pageIndex, int rowCount) {
	String data[][] = this.selectPage(pageSize, pageIndex, rowCount);
	EATMEDICINE obj[] = toObject(data);
	return obj;
}
 /**
 * 分組統計筆數
 * @param fk_List
 * @return
 */
public Map<Integer, Integer> getGroupCount(String fkName, LinkedList<Integer> fk_List){String q = "";
Object parameter[] = new Object[fk_List.size()];
int i=0;
for (Integer no : fk_List) {
q += "?,";
parameter[i++] = no;
}
if (q.length() > 0){
q = q.substring(0, q.length()-1);
}
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();String SQL = "";SQL += "SELECT "+ fkName +", count("+ fkName +") ";SQL += "FROM "+ fn.TABLE_NAME +" where "+fkName+" in (" + q + ")";SQL += "group by "+ fkName +";";String data[][] = super.select(SQL, parameter);for (int j = 0; j < data.length; j++) {int key = Integer.parseInt(data[j][0]);int count = Integer.parseInt(data[j][1]);map.put(key, count);}return map;} /**
 * Where PK in(?,?,?....)
 * @param idList
 * @return
 */
public Map<Integer, EATMEDICINE> selectMap(LinkedList<Integer> idList){
String q = "";
Object parameter[] = new Object[idList.size()];
int i=0;
for (Integer no : idList) {
q += "?,";
parameter[i++] = no;
}
if (q.length() > 0){
q = q.substring(0, q.length()-1);
}
HashMap<Integer, EATMEDICINE> map = new HashMap<Integer, EATMEDICINE>();

String SQL = "select * from EATMEDICINE where idmedicine in ("+ q +")";
String data[][] = super.select(SQL, parameter);
EATMEDICINE[] obj = this.toObject(data);
for (EATMEDICINE o : obj) {
map.put(new Integer(o.idmedicine) , o);
}
return map;
}
public EATMEDICINE[] toObject(String data[][]){
EATMEDICINE[] obj = new EATMEDICINE[data.length];
for (int i = 0; i < obj.length; i++) {
obj[i] = new EATMEDICINE(super.getSetting());obj[i].idmedicine=Integer.parseInt(data[i][0]);
obj[i].onoffmedicine=data[i][1];
obj[i].sun=data[i][2];
obj[i].mon=data[i][3];
obj[i].tue=data[i][4];
obj[i].wed=data[i][5];
obj[i].thu=data[i][6];
obj[i].fri=data[i][7];
obj[i].sat=data[i][8];
obj[i].timemedicine=data[i][9];
obj[i].picturemedicine=data[i][10];
obj[i].audiomedicine=data[i][11];
obj[i].idoldman=Integer.parseInt(data[i][12]);
}
return obj;}
}